<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/common/default.jsp"%>
<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<script type="text/javascript" src="${ctx}/static/tools/jquery-validationEngine/jquery.validationEngine.js"></script>
		<script type="text/javascript" src="${ctx}/static/tools/jquery-validationEngine/jquery.validationEngine-cn.js"></script>
	</head>
	

	<body>
		<div class="breadcrumbs" id="breadcrumbs">
			<script type="text/javascript">
								try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
							</script>
	
			<ul class="breadcrumb">
				<li><i class="icon-home home-icon"></i> <a href="#">首页</a></li>
				<li>用户中心</li>
				<li class="active">教师管理</li>
			</ul>
			<!-- .breadcrumb -->
		</div>	
		<div class="page-content">
			<div class="page-header">
				<h1>教师管理
					<small>
					<i class="icon-double-angle-right"></i>
					查看
					</small>					
				</h1>			
			</div> 
			<div>
				<form  id="searchForm" name="searchForm" role="form" method="post" action="${ctx}/sys/user/listUser">
					<input type="text" id="userName" name="userName" placeholder="姓名" value="${searchForm.userName}" class="col-xs-10 col-sm-1"/>
					<label for="form-field-select-3" style="width:40px;margin-left: 20px" for="gradeId">性别 </label>
					<select  id="sex" name="sex" data-placeholder="请选择">
						<option value="">请选择</option>
						<option value="0"  <c:if test="${searchForm.sex eq '0'}">selected</c:if> >男</option>
						<option value="1" <c:if test="${searchForm.sex eq '1'}">selected</c:if> >女</option>
					</select>
					<label for="form-field-select-3" style="width:60px;margin-left: 10px" for="gradeId">手机号 </label>
					<input type="text" id="phoneNum" name="phoneNum" placeholder="手机号" value="${searchForm.phoneNum}" style="width: 150px"/>
					<label for="form-field-select-3" style="width:40px;margin-left: 10px" for="gradeId">邮箱 </label>
					<input type="text" id="email" name="email" placeholder="邮箱" value="${searchForm.email}" style="width: 150px"/>
					
					<!--<label for="form-field-select-3" style="width:60px;margin-left: 20px" for="orderCode">开始时间 </label>
					<div class="input-group">
					<input class="form-control date-picker" id="id-date-picker-1" type="text" data-date-format="yyyy-mm-dd" />
					<span class="input-group-addon">
																		<i class="icon-calendar bigger-110"></i>
																	</span>  -->
					<input id="sysUserInfoSearch" type="submit" value="查询" style="margin-left: 10px">
					
				</form>				
			</div>
		
		
			<div class="row" >	
			<div class="col-xs-12">
				<table id="simple-table" class="table table-striped table-bordered table-hover"  style="margin-top:5px;">
							<thead>
								<tr>
									<th class="center" style="width: 30px;">
										<label><input class="ace" type="checkbox" id="zcheckbox" /><span class="lbl"></span></label>
									</th>
									<th class='center' style="width:50px;">序号</th>
									<th class="center">用户名</th>
									<th class="center">姓名</th>
									<th class="center">科目</th>
									<th class="center">性别</th>
									<th class="center">电话</th>
									<th class="center">邮箱</th>
<!-- 									<th class="left">角色</th> -->
									<th class="center">是否禁用</th>
									<th class="center" >操作</th>
								</tr>
							</thead>
							<tbody id="userlist">
							<c:forEach var="res" items="${res.data.rows}" varStatus="status">
							<tr  id="userinfo_row_${res.user_id}" >
								<td class="center">
									<label><input type="checkbox" class="ace" /><span class="lbl"></span></label>
								</td>	
								<td class='center' >${ status.index + 1}</td>  							
								<td class='center'>&nbsp;<a href="${ctx}/sys/user/toUpdate/${res.user_id}">${res.loginName}</a></td>
								<td class='center' title="${res.userName}"> &nbsp;${res.userName}</td>
								<td class='center' title="${res.subjectId}"> 
								  	<c:choose>
				                 		<c:when test="${res.subjectId==1}">语文</c:when>
				                 		<c:when test="${res.subjectId==2}">数学</c:when>
				                 		<c:when test="${res.subjectId==3}">英语</c:when>
				                 		<c:otherwise>语文</c:otherwise>
				                 	</c:choose>
								</td>
								<td class='center' title="${res.sex}"> 
								  	<c:choose>
				                 		<c:when test="${res.sex==1}">男</c:when>
				                 		<c:otherwise>女</c:otherwise>
				                 	</c:choose>
								</td>
								<td class='center' title="${res.phoneNum}">&nbsp;${res.phoneNum}</td>
								<td class='center' title="${res.email}"> &nbsp;${res.email}</td>
<%-- 								 <td title="${res.role.roleName}">&nbsp;${res.role.roleName}</td> --%>
				                <td class='center' title="${res.isAvailable}" id="userinfo_row_stats_${res.user_id}">&nbsp;
					                <c:choose>
					                 	<c:when test="${res.isAvailable==0}">是</c:when>
					                 	<c:when test="${res.isAvailable==1}">否</c:when>
					                </c:choose>
				                </td>
				                 <td class='center'>
<%-- 				                 	<a style="margin-left: 3%;" href="${ctx}/sys/user/toUpdate/${res.user_id}" title="${ctx}/sys/user/update/${res.user_id}">编辑</a> --%>
<%-- 				                 	<a style="margin-left: 3%;" href="${ctx}/sys/user/approve?userId=${res.user_id}">审批</a> --%>
<%-- 				                 	<a style="margin-left: 3%;" href="javascript:resetPwd(${res.user_id});">重置密码</a> --%>
<%-- 				                 	<c:choose> --%>
<%-- 				                 		<c:when test="${res.isAvailable==1}"> --%>
<%-- 				                 			<a style="margin-left: 3%;" href="javascript:disableUser(${res.user_id},0);">禁用</a> --%>
<%-- 				                 		</c:when> --%>
<%-- 				                 		<c:when test="${res.isAvailable==0}"> --%>
<%-- 				                 			<a style="margin-left: 3%;" href="javascript:disableUser(${res.user_id},1);">启用</a> --%>
<%-- 				                 		</c:when> --%>
<%-- 				                 	</c:choose> --%>
									<button title="编辑" class="btn btn-xs btn-info" onclick="location='${ctx}/sys/user/toUpdate/${res.user_id}'">
										<i class="icon-edit bigger-120"></i>
									</button>
									<button title="删除" class="btn btn-xs btn-danger" onclick="javascript:deleteuser('${res.user_id}');">
												<i class="icon-trash bigger-120"></i>
									</button>
									
									<button title="重置密码" class="btn btn-xs btn-info" onclick="javascript:resetPwd(${res.user_id});">
												<i class="icon-key bigger-120"></i>
									</button>
								</td>
							</tr> 
							</c:forEach>
							</tbody>
				</table>
				<div style="margin-bottom: 20px">
					<a class="btn btn-sm btn-success" href="${ctx}/sys/user/toAdd">新增</a>
					<a class="btn btn-sm btn-success" href="${ctx}/sys/user/toImport">导入</a>
				</div>	
				
				<%@ include file="/WEB-INF/views/decorators/page.jsp"%> 			 
			</div>
			</div>
			
		</div>
		<script type="text/javascript">
			function deleteuser(userid){
				if(confirm("确认删除该条用户信息？")){
					var data = new Object();
					data.userId = userid;
					 $.ajax({
					        async: true,
					        type:"POST",
					        data:data,
					        url: "${ctx}/sys/user/delete",
					        dataType: "json",
					        success: function (data) {
					    	    if("success" == data.result){//成功
					    	    	alert("删除成功");
					    	    	window.location.href = "${ctx}/sys/user/listUser";
					    	    }else{//失败
					    	    	alert("删除失败");
					    	    }
					        }
						},"json");
				}
			}
			
			function resetPwd(userId){
				if(confirm("您确认重置该用户密码吗?")){
					resetRowById(userId);
				}
			}
			
			//密码重置ajax请求
			function resetRowById(rowId){
				$.ajax({
					type: "POST",
					dataType: "json",
					async: false,
					url: '${ctx}/sys/user/resetPwd/'+rowId,
					success: function (data) {
								if(data!=undefined&&data.status!=undefined&&data.status.trim()=="0"){
									//$("#userinfo_row_"+rowId).remove();
									alert("重置成功。");
								}else{
									alert("error:"+data.error);
								}
							 },
					error: function(data) {
								alert("重置失败。");
							}
				});
				return false;
			}
		
		
		</script>
		
	</body>

</html>
